<!DOCTYPE html>
<!-- 网页使用的语言 -->
<html lang="zh-CN">
<head>
    <!-- 指定字符集 -->
    <meta charset="utf-8">
    <!-- 使用Edge最新的浏览器的渲染方式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- viewport视口：网页可以根据设置的宽度自动进行适配，在浏览器的内部虚拟一个容器，容器的宽度与设备的宽度相同。
    width: 默认宽度与设备的宽度相同
    initial-scale: 初始的缩放比，为1:1 -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>用户信息管理系统</title>

    <!-- 1. 导入CSS的全局样式 -->
    <link href="css/list.css" rel="stylesheet">
    <!-- 字体图标 -->
    <link rel="stylesheet" href="css/fonts.css">
    <link rel="stylesheet" href="fonts/font_2608025_7htl2dz9bkd/iconfont.css">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="js/jquery-2.1.0.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->

    <!--    <%&#45;&#45;${pageContext.request.contextPath}用于解决使用相对路径时出现的问题，它的作用是取出所部署项目的名字&#45;&#45;%>-->
    <script>
        function jump() {
            window.location.href = "/loginServlet";
        }

        function deleteUser(id) {
            //用户安全提示
            if (confirm("您确定要删除吗？")) {
                //访问路径
                location.href = "${pageContext.request.contextPath}/bookDelUserServlet?id=" + id;
            }
        }

        window.onload = function () {
            //给删除选中按钮添加单击事件
            document.getElementById("delSelected").onclick = function () {
                if (confirm("您确定要删除选中条目吗？")) {

                    var flag = false;
                    //判断是否有选中条目
                    var cbs = document.getElementsByName("uid");
                    for (var i = 0; i < cbs.length; i++) {
                        if (cbs[i].checked) {
                            //有一个条目选中了
                            flag = true;
                            break;
                        }
                    }

                    if (flag) {//有条目被选中
                        //表单提交
                        document.getElementById("form").submit();
                    }
                }
            }
            //1.获取第一个cb
            document.getElementById("firstCb").onclick = function () {
                //2.获取下边列表中所有的cb
                var cbs = document.getElementsByName("uid");
                //3.遍历
                for (var i = 0; i < cbs.length; i++) {
                    //4.设置这些cbs[i]的checked状态 = firstCb.checked
                    cbs[i].checked = this.checked;
                }
            }
        }
    </script>
</head>
<body>
<!-- 头部 -->

<div class="container">
    <h3 style="text-align: center; color: #fff">书籍信息列表</h3>

    <div style="float: left;">

        <form class="form-inline" action="${pageContext.request.contextPath}/bookFindUserByPageServlet" method="post">
            <div class="form-group">
                <label for="exampleInputName2">书籍名称</label>
                <input type="text" name="bookName" value="${condition.bookName[0]}" class="form-control"
                       id="exampleInputName2">
            </div>

            <button type="submit" class="btn btn-default">查询</button>
        </form>

    </div>

    <div style="float: right;margin: 5px;">

        <a class="btn btn-primary" href="${pageContext.request.contextPath}/add.jsp">添加书籍</a>
        <a class="btn btn-primary" href="javascript:void(0);" id="delSelected">删除选中</a>

    </div>
    <form id="form" action="${pageContext.request.contextPath}/bookDelSelectedServlet" method="post">
        <table border="1" class="table table-bordered table-hover">
            <tr class="success">
                <th><input type="checkbox" id="firstCb"></th>
                <th>编号</th>
                <th>书名</th>
                <th>状态</th>
                <th>书龄</th>
                <th>作者</th>
                <th>字数</th>
                <th>出版社</th>
                <th>操作</th>
            </tr>
            <!--            <%&#45;&#45;遍历&#45;&#45;%>-->
            <!--            <%&#45;&#45; < c : forEach  var="每个变量名字"   items="要迭代的list"   varStatus="每个对象的状态"&#45;&#45;%>-->

            <!--            <%&#45;&#45; begin="循环从哪儿开始"     end ="循环到哪儿结束"    step="循环的步长">&#45;&#45;%>-->

            <!--            <%&#45;&#45; 循环要输出的东西&#45;&#45;%>-->

            <!--            <%&#45;&#45; </ c : forEach > &#45;&#45;%>-->
            <c:forEach items="${pb.list}" var="book" varStatus="s">
                <tr>
                    <td><input type="checkbox" name="uid" value="${book.id}"></td>
                    <td>${s.count}</td>
                    <td>${book.bookName}</td>
                    <td>${book.state}</td>
                    <td>${book.bookAge}</td>
                    <td>${book.author}</td>
                    <td>${book.wordName}</td>
                    <td>${book.press}</td>
                    <td>
                        <a class="btn btn-default btn-sm"
                           href="${pageContext.request.contextPath}/bookFindUserServlet?id=${book.id}">修改</a>&nbsp;
                        <a class="btn btn-default btn-sm" href="javascript:deleteUser(${book.id});">删除</a>
                    </td>
                </tr>
            </c:forEach>


        </table>
    </form>
    <div>
        <nav aria-label="Page navigation">
            <ul class="pagination">
                <c:if test="${pb.currentPage == 1}">
                    <li class="disabled">
                </c:if>
                <c:if test="${pb.currentPage != 1}">
                    <li>
                </c:if>
                <a href="${pageContext.request.contextPath}/bookFindUserByPageServlet?currentPage=${pb.currentPage - 1}&rows=5&bookName=${condition.bookName[0]}&author=${condition.press[0]}&email=${condition.press[0]}"
                   aria-label="Previous">
                    <span aria-hidden="true" class="pq">&laquo;</span>
                </a>
                </li>
                <c:forEach begin="1" end="${pb.totalPage}" var="i">
                    <c:if test="${pb.currentPage == i}">
                        <li class="active"><a
                                href="${pageContext.request.contextPath}/bookFindUserByPageServlet?currentPage=${i}&rows=5&bookName=${condition.bookName[0]}&author=${condition.author[0]}&press=${condition.press[0]}">${i}</a>
                        </li>
                    </c:if>
                    <c:if test="${pb.currentPage != i}">
                        <li>
                            <a href="${pageContext.request.contextPath}/bookFindUserByPageServlet?currentPage=${i}&rows=5&bookName=${condition.bookName[0]}&author=${condition.author[0]}&press=${condition.press[0]}">${i}</a>
                        </li>
                    </c:if>

                </c:forEach>

                <li>
                    <a href="${pageContext.request.contextPath}/bookFindUserByPageServlet?currentPage=${pb.currentPage + 1}&rows=5&bookName=${condition.bookName[0]}&author=${condition.author[0]}&press=${condition.press[0]}"
                       aria-label="Next">
                        <span aria-hidden="true" class="pq">&raquo;</span>
                    </a>
                </li>
                <span style="font-size: 25px;margin-left: 5px;">
                    共${pb.totalCount}条记录，共${pb.totalPage}页
                </span>

            </ul>
        </nav>
    </div>
</div>
</body>
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>
<script src="js/content.min.js?v=1.0.0"></script>
</html>